Ext.define('App.datacollection.finished.view.TaskResultList', {
    extend: 'Extend.grid.CrudGridPanel',
    alias: 'widget.TaskResultList',
    requires: ['App.datacollection.finished.model.TaskResultViewModel'],
    viewModel: 'TaskResultViewModel',
    bind: {
        store: '{Query}',
        columns: '{columns}',
        search: '{search}'
    },
    config: {
        tbar: {
            quickCreate: {
                hidden: false
            },
            stop: {
                text: "停止",
                handler: function () {
                    var me = this.up('CrudGridPanel');
                    me.stopHandler.call(me);
                }
            }
        }
    },
    editor: {
        formClazz: 'App.datacollection.finished.view.TaskResultEditor',
        save: 'collection/task_result/save',
        get: 'collection/task_result/get_by_id',
        del: 'collection/task_result/deletes',
        model: 'App.datacollection.finished.model.TaskResultModel'
    },
    addHandler: function () {
        this.editHandler(null, false, {
            project: {
                id: this.projectId
            },
            repeatMode: '每周',
            disabled: false
        });
    },
    stopHandler: function () {
        var me = this;
        var selection = me.getSelectionModel().getSelection();
        if (selection.length > 0) {
            var data = selection[0].data;
            Ext.Ajax.request({
                url: 'datacollection/job/stop_job',
                params: {
                    // name: data.name,
                    // group: data.projectId,
                    taskInstanceId: data.id
                },
                success: function (resp) {
                    try {
                        if (resp.result.success) {
                            me.reload();
                        }
                    } finally {
                        me.unmask();
                    }
                },
                failure: function () {
                    me.unmask();
                }
            });
        }
    }
});